In [1]:
from fraude.catalog import load_model_metrics
from fraude.viz import plot_confussion
from pathlib import Path
import pandas as pd
In [2]:
project_path = Path('..').resolve()
In [3]:
model_metrics = load_model_metrics(project_path)
In [4]:
test_metrics = model_metrics['test']
train_metrics = model_metrics['train']
confusion_matrix = {key: value for key, value in test_metrics.items() if key in ['tn', 'fp', 'fn', 'tp']}
real = {
"fn": "Fraude real",
"fp": "No fraude real",
"tn": "No fraude real",
"tp": "Fraude real"
}
predicted = {
"fn": "No fraude predicho",
"fp": "Fraude predicho",
"tn": "No fraude predicho",
"tp": "Fraude predicho"
}
values = confusion_matrix.values()
labels = confusion_matrix.keys()
real_column = [real[x] for x in labels]
predicted_column = [predicted[x] for x in labels]
confussion_table = pd.DataFrame({"value": values, "label": labels, "real": real_column, "predicted": predicted_column})
In [5]:
confussion_table
Out[5]:
| value | label | real | predicted | |
|---|---|---|---|---|
| 0 | 15440.0 | fn | Fraude real | No fraude predicho |
| 1 | 50282.0 | fp | No fraude real | Fraude predicho |
| 2 | 110384.0 | tn | No fraude real | No fraude predicho |
| 3 | 34016.0 | tp | Fraude real | Fraude predicho |
In [7]:
plot_confussion(
confussion_table,
horizontal_column='real',
vertical_column='predicted',
label_column='label',
value_column='value',
horizontal_ascending=True,
vertical_ascending=False
)